const http=require("http");
const fs=require("fs")

function sendPage(req,res){
    let fileContent=fs.readFileSync("post.html");
    res.end(fileContent)
}

function postData(req,res){
    let str="";
    req.on("data",(chunk)=>{
        str+=chunk
    })
    req.on("end",()=>{
        console.log(str);
        res.end("received post data");
    })
}

http.createServer((req,res)=>{
    switch(req.method){
        case "GET":
            sendPage(req,res);
            break;
        case "POST":
            postData(req,res);
            break;
    }
}).listen(3000)